package team.lourd.network.system.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
* @Description: 采用多数据源,分别连接network_system和telecom
* 并且为动态查询使用自定义Repository使用实体管理器(Entity Manager)
* @Author: Lourd
* @Date:  2019/1/17
*/
@Configuration
public class DataSourceConfig {

    @Primary    //配置该数据源为主数据源
    @Bean(name = "networkSystemDataSource")
    @Qualifier(value = "networkSystemDataSource")
    @ConfigurationProperties(prefix = "spring.primary.datasource")
    public DataSource mysqlDataSource(){
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "telecomDataSource")
    @Qualifier(value = "telecomDataSource")
    @ConfigurationProperties(prefix = "spring.secondary.datasource")
    public DataSource oracleDataSource(){
        return DataSourceBuilder.create().build();
    }
}
